package array;

public class RemoveDuplicatesFromSortedArrayii80 {
    public int removeDuplicates(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        int index = 0;
        int count = 1;
        for (int i = 1; i < nums.length; i++) {
            int c = nums[i];
            if (c == nums[index] && count < 2) {
                nums[++index] = c;
                count++;
            }
            if (c != nums[index]) {
                nums[++index] = c;
                count = 1;
            }
        }
        return index + 1;
    }
}
